<template>
  <div>
    <TodoTou @addList="addList"></TodoTou>
    <TodoTi
      :list="renderList"
      @changeFlag="changeFlag"
      @belBtn="belBtn"
      @changeAll="changeAll"
    ></TodoTi>
    <TodoWei
      @clearQingchu="clearQingchu"
      :sum="sum"
      :isShow="isShow"
      :type="type"
      @comporType="comporType"
    ></TodoWei>
  </div>
</template>

<script>
import TodoTou from './components/TodoTou.vue'
import TodoTi from './components/TodoTi.vue'
import TodoWei from './components/TodoWei.vue'
export default {
  components: { TodoTou, TodoTi, TodoWei },
  props: {},
  data() {
    return {
      list: [
        {
          flag: true,
          name: '睡觉',
          id: 1,
        },
        {
          flag: true,
          name: '躺平',
          id: 2,
        },
        {
          flag: false,
          name: '摆烂',
          id: 3,
        },
      ],
      type: 'all',
    }
  },
  computed: {
    sum() {
      return this.list.filter((item) => !item.flag).length
    },
    isShow() {
      return this.list.some((item) => item.flag)
    },
    renderList() {
      switch (this.type) {
        case 'all':
          return this.list
        case 'active':
          return this.list.filter((item) => !item.flag)
        case 'completed':
          return this.list.filter((item) => item.flag)
        default:
          return this
      }
    },
  },
  watch: {
    
  },
  methods: {
    addList(name) {
      this.list = [...this.list, { flag: false, name: name, id: +new Date() }]
    },
    changeFlag(id, flag) {
      this.list.forEach((item) => {
        if (item.id === id) item.flag = flag
      })
    },
    belBtn(id) {
      this.liet.filter((item) => item.id !== id)
    },
    clearQingchu() {
      this.list = this.list.filter((item) => !item.flag)
    },
    changeAll(flag) {
      this.list.forEach((item) => (item.flag = flag))
    },
    comporType(name) {
      this.type = name
    },
  },
}
</script>

<style scoped></style>
